<?php

namespace App\Logging;

use Illuminate\Support\Facades\Storage;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;

class CustomLogHandler extends AbstractProcessingHandler
{
    public function __construct($level = Logger::DEBUG, $bubble = true)
    {
        parent::__construct($level, $bubble);
        // 自定义的构造函数逻辑
    }

    protected function write(array $record): void
    {
        $cLogPath = Storage::path('cLog');
        if(!is_dir($cLogPath)){
            mkdir($cLogPath);
        }
        // 写入日志文件或其他存储方式
        $path = $cLogPath.DIRECTORY_SEPARATOR.date("Ymd");
        if(!is_dir($path)){
            mkdir($path);
            touch($path.DIRECTORY_SEPARATOR."clog.txt");
        }
        file_put_contents($path.DIRECTORY_SEPARATOR."clog.txt", $record['formatted'].PHP_EOL
, FILE_APPEND);
    }
}
